package com.css.zfzx.fwsjcj.modules.taskmanage.task.repository;

import com.css.zfzx.fwsjcj.commen.util.Constant;
import com.css.zfzx.fwsjcj.modules.taskmanage.task.entity.FwTaskEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface TaskRepository extends JpaRepository<FwTaskEntity, String> {

    @Modifying
    @Query(nativeQuery = true, value = "update fw_task set group_id =:groupId,group_leader =:groupLeader,group_leader_mobile =:mobilePhon,group_name =:groupName,status = " + Constant.TASK_STATUS_DONING + ",group_leader_id=:groupLearderId where task_id =:id")
    void updateTask(@Param("groupId") String groupId, @Param("id") String id, @Param("groupLeader") String groupLeader, @Param("mobilePhon") String mobilePhon, @Param("groupName") String groupName, @Param("groupLearderId") String groupLearderId);

    @Modifying
    @Query(nativeQuery = true, value = "update fw_task set del_flag ='" + Constant.IS_VALID_NO + "' where task_id in :ids")
    void deleteTask(@Param("ids") List<String> ids);

    /**
     * 任务完成后，并且修改质检状态为1：可以发配质检员
     *
     * @param type
     * @param qualityStatus 质检状态
     * @param taskId
     */
    @Modifying
    @Query(nativeQuery = true, value = "update fw_task set status =:type, quality_status =:qualityStatus where task_id =:taskId")
    void completeTask(@Param("type") String type, @Param("qualityStatus") String qualityStatus, @Param("taskId") String taskId);

    @Query(nativeQuery = true, value = "select * from fw_task where del_flag =" + Constant.IS_VALID_YES + " and task_type = " + Constant.TASK_TYPE_PU)
    List<FwTaskEntity> findAllVild();
    @Query(nativeQuery = true, value = "select * from fw_task where del_flag =" + Constant.IS_VALID_YES + " and task_type = " + Constant.TASK_TYPE_JG)
    List<FwTaskEntity> findJGVild();
    @Query(nativeQuery = true, value = "select * from fw_task where del_flag =" + Constant.IS_VALID_YES + " and task_name =:taskName")
    FwTaskEntity findbyName(@Param("taskName") String taskName);
}
